package com.ly.video.common.util;

import java.util.Random;

public class WeightUtil {

    /**
     * 观看视频权重计算
     */
    public static int watchVideoWeight(int weight){
        if (weight <= 300) {
            weight += new Random().nextInt(100);
            return weight;
        }
        if (weight <= 1000) {
            return weight - new Random().nextInt(300);
        }
        // 随机数计算权重
        int random = new Random().nextInt(1000);
        if(random < 300){
            return weight - random;
        } else {
            return weight - ((1000 - random) / 2);
        }
    }

    /**
     * 徒弟观看视频计算权重
     */
    public static int sonWatchWeight(int weight){
        weight += weight*0.01;
        if (weight >= 3000) {
            return 3000;
        }
        return weight;
    }

    /**
     * 观看其他广告添加权重
     */
    public static int adsWeight(int weight){
        if (weight <= 1000) {
            weight += (int)(weight * 0.1);
        }
        if (weight <= 2000 && weight > 1000) {
            weight += (int)(weight * 0.05);
        }
        if (weight < 3000 && weight > 2000){
            weight += (int)(weight * 0.01);
        }
        if (weight >= 3000) {
            return 3000;
        }
        return weight;
    }
}
